package com.lms.common.pure.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.stream.Stream;

public class ReflectUtil {

    public static Class<?> getEntityType(Class<?> clazz, int index) {
        Type[] types = clazz.getGenericInterfaces();
        Type type = clazz.getGenericSuperclass();
        if (type instanceof ParameterizedType parameterizedType) {
            Stream.of(parameterizedType.getActualTypeArguments()).forEach(System.out::println);
            return (Class<?>) parameterizedType.getActualTypeArguments()[index];
        }
        if (types[0] instanceof ParameterizedType parameterizedType) {
            Stream.of(parameterizedType.getActualTypeArguments()).forEach(System.out::println);
            return (Class<?>) parameterizedType.getActualTypeArguments()[index];
        }
        return null;
    }
}
